package com.third.githublogin.oauth.service;

import com.third.githublogin.model.OAuthUser;
import org.scribe.model.OAuthRequest;
import org.scribe.model.Token;
import org.scribe.model.Verifier;
import org.scribe.oauth.OAuthService;


/**
 * getoAuthType() 获取该Service的type
 * getAuthorizationUrl() 获取authorizationUrl，方便前端展示
 * getOAuthUser(Token accessToken) 根据access token拿到用户资源，并将其转换为对应的OAuthUser
 */
public abstract class OAuthServiceDeractor implements OAuthService {
    private final OAuthService oAuthService;
    private final String oAuthType;
    private final String authorizationUrl;

    public OAuthServiceDeractor(OAuthService oAuthService, String type) {
        this.oAuthService = oAuthService;
        this.oAuthType = type;
        this.authorizationUrl = oAuthService.getAuthorizationUrl(null);
    }

    @Override
    public Token getRequestToken() {
        return oAuthService.getRequestToken();
    }

    @Override
    public Token getAccessToken(Token requestToken, Verifier verifier) {
        return oAuthService.getAccessToken(requestToken,verifier);
    }

    @Override
    public void signRequest(Token accessToken, OAuthRequest request) {
        oAuthService.signRequest(accessToken,request);
    }

    @Override
    public String getVersion() {
        return oAuthService.getVersion();
    }

    @Override
    public String getAuthorizationUrl(Token requestToken) {
        return oAuthService.getAuthorizationUrl(requestToken);
    }

    public String getoAuthType() {
        return oAuthType;
    }

    public String getAuthorizationUrl() {
        return authorizationUrl;
    }

    public abstract OAuthUser getOAuthUser(Token accessToken);
}
